<?php require_once VIEWPATH . 'common/header.php'; ?>
<body>
<div class="page-container">
    <form class="form form-horizontal">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>合同号：</label>

            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" disabled class="input-text" value="<?=$contract_number ?? '' ?>" placeholder="" id="contract_number">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>快递：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width:25%">
                <select id="provider" class="select">
                    <?php foreach($express_list as $express):?>
                        <option <?php if($express['name'] == ($provider??'')):?>selected<?php endif;?> value="<?=$express['name']?>"><?=$express['name']?></option>
                    <?php endforeach;?>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>物流单号：</label>

            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<?=$express_number ?? '' ?>" placeholder="" id="express_number" name="" style="width:90%">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>运费销售单价：</label>

            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="<?=$unit_selling_price ?? '' ?>" placeholder="" id="unit_selling_price" name=""
                       style="width:90%">&nbsp;&nbsp;元
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>运费采购单价：</label>

            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" name="" id="purchase_price" placeholder="" value="<?=$purchase_price ?? '' ?>" class="input-text"
                       style="width:90%">&nbsp;&nbsp;元
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">备注：</label>

            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="remark" name="" cols="" rows="" class="textarea" placeholder="说点什么...最少输入10个字符" datatype="*10-100" dragonfly="true"> <?=$remark ?? '' ?></textarea>
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <span onClick="save();" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe632;</i> 保存
                </span>
                <span onClick="layer_close();" class="btn btn-default radius">&nbsp;&nbsp;取消&nbsp;&nbsp;</span>
            </div>
        </div>
        <input type="hidden" id="bill_id" value="<?=$bill_id??''?>">
    </form>
</div>
<?php require_once VIEWPATH . 'common/footer.php'; ?>
</body>
</html>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">

    mustNum($("#purchase_price"));
    mustNum($("#unit_selling_price"));

    function mustNum($object){
        $object.bind({
                keyup:function(){
                     var txt = $object.val();
                     var reg = /^[\d]+$/;
                     if(!reg.test(txt) ){
                            $(this).val('');
                     }
                },
                focus:function(){
                    if ($(this).val() == 0){
                        $(this).val('');
                    }
                },
                blur:function(){
                    if ($(this).val() == ''){
                        $(this).val('');
                    }
                }
        }); 
    }
    
    function save() {
        var bill_id = $("#bill_id").val();
        var contract_number = $("#contract_number").val();
        var provider = $("#provider").val();
        var unit_selling_price = $("#unit_selling_price").val();
        var purchase_price = $("#purchase_price").val();
        var remark = $("#remark").val();
        var express_number = $("#express_number").val();
        var params = {
            contract_number:contract_number,
            provider: provider,
            unit_selling_price: unit_selling_price,
            purchase_price: purchase_price,
            remark:remark,
            express_number:express_number
        };
        if(bill_id){
            params.bill_id = bill_id;
        }
        $.post("/bill/updateExpress", params, function (data) {
            if (data.code != 1) {
                layer.msg(data.message);
            }
            layer.msg(data.message);
            parent.location.reload();
        },'json');
    }
</script>

